package cn.dw.utils;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class BeanTool {
	public static String[] getNullProperties(Object obj) {
		List<String> nameList = new ArrayList<>();
		try {
			BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());

			PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
			if (pds != null) {
				for (PropertyDescriptor pd : pds) {
					Method readMethod = pd.getReadMethod();

					Object returnValue = readMethod.invoke(obj, new Object[0]);
					if (returnValue == null) {
						nameList.add(pd.getName());
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		String[] arr = new String[nameList.size()];
		for (int i = 0; i < nameList.size(); i++) {
			arr[i] = ((String) nameList.get(i));
		}
		return arr;
	}
}
